package com.indeep.user.common;


import org.springframework.http.HttpStatus;

import java.io.Serializable;

public class JsonResult<E> implements Serializable {
    private Integer code;
    private String message;
    private E content;

    public JsonResult() {
    }

    //获取异常时用
    public JsonResult(Throwable e) {
        //获取异常信息
        this.message = e.getMessage();
    }

    public JsonResult(Integer code) {
        this.code = code;
    }

    public JsonResult(String message) {
        this.message = message;
    }

    public JsonResult(E content) {
        this.content = content;
    }

    public JsonResult(Integer code, String message, E content) {
        this.code = code;
        this.message = message;
        this.content = content;
    }

    public JsonResult(HttpStatus status, E content) {
        this.code = status.value();
        this.message = status.getReasonPhrase();
        this.content = content;
    }

    public JsonResult(StatusCode statusCode) {
        this.code = statusCode.code;
        this.message = statusCode.msg;
    }

    public JsonResult(StatusCode statusCode, E content) {
        this.code = statusCode.code;
        this.message = statusCode.msg;
        this.content = content;
    }

    public JsonResult(Integer code, E content) {
        this.code = code;
        this.content = content;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public E getContent() {
        return content;
    }

    public void setContent(E content) {
        this.content = content;
    }

//    @Override
//    public String toString() {
//        return JSON.toJSONString(this);
//    }
}